﻿using System;
using System.Collections;
using System.IO;
using log4net.Core;
using log4net.Layout.Pattern;

namespace Utils
{
	public sealed class ExceptionDataPatternConverter : PatternLayoutConverter
	{
		protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
		{
			if (loggingEvent.ExceptionObject != null)
			{
				IDictionary data = loggingEvent.ExceptionObject.Data;
				if (data != null)
				{
					foreach (var key in data.Keys)
					{
						writer.Write("Data[{0}]={1}" + Environment.NewLine, key, data[key]);
					}
				}
			}
		}
	}
}